# import pymysql
# try:
#     connect = pymysql.connect(
#         host="127.0.0.1",
#         user="root",
#         password="root",
#         db="wo",
#         charset="utf8",)
#     cursor = connect.cursor()
#     sql = "insert into teacherinfo(tno,tname) values('03070','周勇')"
#     cursor.execute(sql)
#     connect.commit()
# except Exception as err:
#     connect.rollback()
#     print(err)
# finally:
#     cursor.close()
#     connect.close()







# import pymysql
# try:
#     connect = pymysql.connect(
#         host="127.0.0.1",
#         user="root",
#         password="root",
#         db="wo",
#         charset="utf8",)
#     cursor = connect.cursor()
#     sql = "insert into teacherinfo(tno,tname) values(%s,%s)"
#     val=[["03072","yongzhou"],["03073","yongzhou"]]
#     cursor.executemany(sql,val)
# except Exception as err:
#     connect.rollback()
#     print(err)
# finally:
#     cursor.close()
#     connect.close()












# import pymysql
# try:
#     connect = pymysql.connect(
#         host="127.0.0.1",
#         user="root",
#         password="root",
#         db="wo",
#         charset="utf8",)
#     cursor = connect.cursor()
#     sql = "insert into teacherinfo(tno,tname) values(%s,%s)"
#     val = ["03072","yongzhou"]
#     cursor.execute(sql,val)
# except Exception as err:
#     connect.rollback()
#     print(err)
# finally:
#     cursor.close()
#     connect.close()





# import pymysql
# try:
#     connect=pymysql.connect(
#         host="127.0.0.1",
#         user="root",
#         password="root",
#         db="wo",
#         charset="utf8",
#         cursorclass=pymysql.cursors.DictCursor
#     )
#     cursor=connect.cursor()
#     sql="select * from teacherinfo"
#     cursor.execute(sql)
#     print(cursor.fetchall())
# except Exception as err:
#     connect.rollback()
#     print(err)
# finally:
#     cursor.close()
#     connect.close()

import pymysql

def save_mysql(sql,val,**dbinfo):
    try:
        connect=pymysql.connect(**dbinfo)
        cursor=connect.cursor()
        cursor.executemany(sql,val)
        connect.commit()
    except Exception as e:
        connect.rollback()
        print(e)
    finally:
        cursor.close()
        connect.close()
if __name__ == '__main__':
    data={
        'host':'127.0.0.1',
        'user':'root',
        'password':'root',
        'db':'wo',
        'charset':'utf8',
        'cursorclass':pymysql.cursors.DictCursor
    }
sql = 'insert into teacherinfo(tno,tname) values(%s,%s)'
values=[["000","en"],["222","hh"]]
save_mysql(sql,values,**data)